package com.example.sprintboot.service;

import com.example.sprintboot.entity.Book;
import com.example.sprintboot.mapper.BookMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {

    @Resource
    private BookMapper bookMapper;

    // 查询所有书籍
    public List<Book> selectAll() {
        return bookMapper.selectAll();
    }

    // 根据 ID 查询书籍
    public Book selectById(Integer id) {
        return bookMapper.selectById(id);
    }

    public List<Book> searchByName(String name) {
        return bookMapper.searchByName(name);
    }

    // 新增书籍
    public void add(Book book) {
        bookMapper.insert(book);
    }

    // 更新书籍信息
    public void update(Book book) {
        bookMapper.updateById(book);
    }

    // 根据 ID 删除书籍
    public void deleteById(Integer id) {
        bookMapper.deleteById(id);
    }
}